package com.bicon.im.service.wcc;


import com.alibaba.fastjson.JSONObject;
import com.bicon.im.service.processor.rpc.handler.ThirdPartRpc;
import com.bicon.life.core.base.common.entity.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 * @author 张露晨
 * @date 2017/10/11 10:40.
 */
@Component
public class RedisMessageListener implements MessageListener {

    @Value("${rpc.repeat.times}")
    int rpcRepeatTimes;

    @Autowired
    private ThirdPartRpc thirdPartRpc;


    @Override
    public void onMessage(final Message message, final byte[] pattern) {
        System.out.println("Message received: " + message.toString());
        test();
    }


    public void test() {
        for (int i = 0; i < 10; i++) {
            String baseResultJson = thirdPartRpc.sendYunSms("13259958658", "我等！", "login");
            BaseResult baseResult = JSONObject.parseObject(baseResultJson, BaseResult.class);
            if (200 == baseResult.getCode()) {
                break;
            }
        }
    }

}